<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/commons/taglibs.jsp" %>
<style>
    #searchBox {
        padding: 25px;
        font-weight: bold;
    }

    #searchBox input {
        margin-right: 20px;
    }
</style>
<form id="inputForm" class="well form-inline" action="${ctx}/point/service/chargePoints" method="post">
    <table class="table table-striped table-bordered table-condensed">
        <tr>
            <th style="text-align: center;">
                <h4>400电话积分控制台</h4>
            </th>
        </tr>
        <tr>
            <td align="center" class="salebox well">
                <div id="searchBox">
                    会员账号(电话):
                    <input id="mobile" name="mobile" class="input-medium" type="text"/>
                    积分码:
                    <input id="iCode" class="input-medium" name="iCode" type="text" maxlength="80"/>
                    <button class="btn btn-info" id="query" type="button">查询</button>
                    <a href="${ctx }/point/service/charge" class="btn">清空数据</a>
                </div>
                <table class="table table-condensed table-bordered table-condensed" id="salebox">
                    <tr>
                        <th class="span2" valign="top">商品详情</th>
                        <td id="qrGoodsCodeDetail">
                            <span class="tBlue">请录入商品积分码进行查询</span>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top">会员信息</th>
                        <td id="memberDetail">
                            <span class="tBlue">暂无该会员信息</span>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top">
                            积分记录
                            <br/>
                            <span style="color: blue; font-weight: normal;">(只显示最近3条记录)</span>
                        </th>
                        <td id="memberRecords">
                            <span class="tBlue">暂无该会员积分记录</span>
                        </td>
                    </tr>
                    <tr>
                        <th valign="top">
                            短信通知
                            <br/>
                            <label class="radio">
                                <input type="radio" checked="checked" value="true" name="sNotice"/>
                                是
                            </label>
                            <label class="radio">
                                <input type="radio" value="false" name="sNotice"/>
                                否
                            </label>
                        </th>
                        <td>

                            <table class="table table-condensed table-bordered table-condensed">
                                <tr>
                                    <td width="60" style="text-align: right;">手机号</td>
                                    <td>
                                        <input id="sMobile" maxlength="11" name="sMobile" type="text">
                                    </td>
                                </tr>
                                <tr>
                                    <td width="60" style="text-align: right;" valign="top">短信内容</td>
                                    <td>
                                        <textarea id="sContent" name="sContent" rows="4" class="span6"></textarea>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td align="center">
                <input class="btn btn-primary span2" id="submitBtn" disabled="disabled" type="submit" value="提交并积分"/>
            </td>
        </tr>
    </table>
</form>
<script>
    $(function () {
        $("#query").click(function () {
            var mobile = $("#mobile").val();
            var iCode = $("#iCode").val();
            if (!mobile) {
                $("#mobile").focus();
                return false;
            }
            if (!iCode) {
                $("#iCode").focus();
                return false;
            }
            $("#qrGoodsCodeDetail").load("${ctx}/adoms/qrGoodsCode/getQrGoodsByICode/" + iCode, function () {
                if (mobile) {

                    $("#memberDetail").load("${ctx}/point/member/detail/" + mobile, function () {
                        var qrGoodsCodeID = $("#qrGoodsCodeID").val();
                        var pointMemberID = $("#pointMemberID").val();
                        if (qrGoodsCodeID) {

                            $("#cPoint").keyup(function () {
                                var sMobile = $.trim(mobile);
                                var cPoint = $.trim($("#cPoint").val());
                                var sContent = "";

                                if (!cPoint) {
                                    $("#cPoint").focus();
                                    $("#submitBtn").attr("disabled", "disabled");
                                    return false;
                                }

                                var balance = $.trim($("#pointMemberBalance").html());
                                if (balance) {
                                    balance = parseFloat($("#pointMemberBalance").html());
                                    balance += parseFloat(cPoint);
                                } else {
                                    balance = parseFloat(cPoint);
                                }

                                if (!pointMemberID) {
                                    sContent = "尊敬的客户，您已成功积分" + cPoint + "分，兑换规则可登录www.alvinbaby.com查询。客服热线4000-800-866【艾唯】。";
                                } else {
                                    sContent = "尊敬的客户，您已成功积分" + cPoint + "分，目前积分余额为" + balance + "分。客服热线4000-800-866【艾唯】。";
                                }

                                $("#submitBtn").removeAttr("disabled");
                                $("#sMobile").val(sMobile);
                                $("#sContent").val(sContent);
                            });
                            $("#cPoint").keyup();

                        } else {
                            $("#submitBtn").attr("disabled", "disabled");
                            $("#sMobile").val("");
                            $("#sContent").val("");
                        }


                        var userName = $("#userName").html();

                        var recordUrl = "${ctx}/point/record/list?compositorType=DESC&fieldName=insertTime&filter_LIKES_member.userName=" + userName + "&pageNo=1 #tableList";
                        $("#memberRecords").load(recordUrl, function () {
                            $("#tableList tr").each(function (i, item) {
                                if (i > 3) {
                                    $(item).remove();
                                }
                            });
                        });
                    });

                }
            });

        });

        $("#inputForm").submit(function () {
            $("#submitBtn").hide().parent().append("数据提交中，请稍后...");
        });

        //为inputForm注册validate函数
        $("#inputForm").validate({
            rules: {
                sMobile: {
                    //required : true,
                    number: true,
                    minlength: 11
                },
                mobile: {
                    //required : true,
                    number: true,
                    minlength: 11
                }
            },
            messages: {
                sMobile: {
                    minlength: "请输入正确的手机号",
                    number: "请输入正确的手机号",
                    marlength: "请输入正确的手机号"
                },
                mobile: {
                    minlength: "请输入正确的手机号",
                    number: "请输入正确的手机号",
                    marlength: "请输入正确的手机号"
                }
            }
        });
    });
</script>
<c:if test="${msg != null}">
    <script>
        msgAlert.show("${msg}");
    </script>
</c:if>